package zdc.ui {
import com.greensock.TweenLite;

import flash.display.DisplayObject;
import flash.events.MouseEvent;

/**
 *
 * @author Metal Slime
 */
public class SwipeInertia extends MovingInertia {
    private var _xtw:TweenLite;
    private var _ytw:TweenLite;

    private var _xTimeRate:Number = 7;
    private var _yTimeRate:Number = 15;
    private var _xDistRate:Number = 40;
    private var _yDistRate:Number = 40;

    protected var _dFunHook:Function;
    protected var _uFunHook:Function;
    protected var _mFunHook:Function;

    public function SwipeInertia(evtTarget:DisplayObject, actTarget:DisplayObject = null, downEvt:String = "", upEvt:String = "", movEvt:String = "", outEvt:String = "", dir:String = "h") {
        super(evtTarget, actTarget, downEvt, upEvt, movEvt, outEvt, dir);
        addDownHook(stopTween);
        addUpHook(startTween);
        addMoveHook(moveTarget);
    }

    private function stopTween(e:Object):void {
        _tw && _tw.kill();
        _dFunHook && _dFunHook();
    }

    private function startTween(e:Object, totalTime:Number, totalDx:Number, totalDy:Number):void {
        if (isH) {
            var xtt:Number = Math.abs(totalDx / totalTime / _xTimeRate);
            var dx:Number = totalDx / totalTime * _xDistRate;
            _xtw = TweenLite.to(_actTarget, xtt, { x: _actTarget.x + dx });
        }
        if (isV) {
            var ytt:Number = Math.abs(totalDy / totalTime / _yTimeRate);
            var dy:Number = totalDy / totalTime * _yDistRate;
            _ytw = TweenLite.to(_actTarget, ytt, { y: _actTarget.y + dy });
        }

        _uFunHook && _uFunHook();
    }

    private function moveTarget(e:Object, dx:Number, dy:Number):void {
        _actTarget.x += dx;
        _actTarget.y += dy;
        _mFunHook && _mFunHook();
    }

    /**
     * x轴得到总移动距离与总时间相除结果后相除的率
     */
    public function get xTimeRate():Number {
        return _xTimeRate;
    }

    public function set xTimeRate(value:Number):void {
        _xTimeRate = value;
    }

    /**
     * y轴得到总移动距离与总时间相除结果后相除的率
     */
    public function get yTimeRate():Number {
        return _yTimeRate;
    }

    public function set yTimeRate(value:Number):void {
        _yTimeRate = value;
    }

    /**
     * x轴得到总移动距离与总时间相除结果后相乘的率
     */
    public function get xDistRate():Number {
        return _xDistRate;
    }

    public function set xDistRate(value:Number):void {
        _xDistRate = value;
    }

    /**
     * y轴得到总移动距离与总时间相除结果后相乘的率
     */
    public function get yDistRate():Number {
        return _yDistRate;
    }

    public function set yDistRate(value:Number):void {
        _yDistRate = value;
    }

    public function get dFunHook():Function {
        return _dFunHook;
    }

    public function set dFunHook(value:Function):void {
        _dFunHook = value;
    }

    public function get uFunHook():Function {
        return _uFunHook;
    }

    public function set uFunHook(value:Function):void {
        _uFunHook = value;
    }

    public function get mFunHook():Function {
        return _mFunHook;
    }

    public function set mFunHook(value:Function):void {
        _mFunHook = value;
    }


}

}